< previous page page_171 next page >

Page 171
9f31265bb40b592b1929e18a47ab28e5.gif
Function FormCheck () As Integer
   FormCheck = False

   If Trim$(txtState.Text) = "" Then
      MsgBox "State Code Must Be Filled In"
      txtState.SetFocus
      Exit Function
   ElseIf Trim$(txtCompany.Text) = "" Then
      MsgBox "Company Name Must Be Filled In"
      txtCompany.SetFocus
      Exit Function
   End If

   FormCheck = True
End Function
In the preceding FormCheck() function, the FormCheck = True line has been moved to the bottom of the function. The FormCheck = False line is set at the top of the function. If one of the tests fails and you need to exit the function, the FormCheck = True line never gets executed.
With . . . End With
Another construct that will come in handy is the With...End With statement. This statement allows you to set multiple properties for one object without specifying the object name over and over again. Take the following code as an example:
9f31265bb40b592b1929e18a47ab28e5.gif
frmEmployee1.Top = 0
frmEmployee1.Left = 0
frmEmployee1.Caption = "With...End With Example"
frmEmployee1.WindowState = vbMaximized
frmEmployee1.Show
Examples Filename: Main.frm
Instead of having to specify the form name, frmEmployee1, over and over again, you can use the following code. Double-click on the With...End With command button on Main.frm to see the following code:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdWith_Click()
   With frmEmployee1
      .Top = 0

 
< previous page page_171 next page >

If you like this book, buy it!